package com.ruoyi.purchase.domain;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.ruoyi.common.annotation.Excel;
import com.ruoyi.common.core.domain.BaseEntity;

import java.util.ArrayList;
import java.util.List;

/**
 * detail对象 change_detail
 * 
 * @author kevinness
 * @date 2025-01-05
 */
public class ChangeDetail extends BaseEntity
{
    private static final long serialVersionUID = 1L;

    /** 变更编号 */
    private Integer id;

    /** 订单编号 */
    private String orderNo;

    /** 采购负责人 */
    private String responsiblePerson;

    /** 联系电话 */
    private String contactPhone;

    /** 交货地点 */
    private String deliveryAddress;

    /** 交货地点经度 */
    private double destinationLng;

    /** 交货地点纬度 */
    private double destinationLat;

    /** 备注 */
    private String remarks;

    /** 订单详情 */
    private String orderDetail;

    /** 变更详情 */
    @Excel(name = "变更详情")
    private String changeDetail;

    /** 变更人 */
    @Excel(name = "变更人")
    private String changePerson;

    /** 变更时间 */
    @Excel(name = "变更时间")
    private String changeTime;

    /** 变更人身份（供货商、运营商） */
    @Excel(name = "变更人身份", readConverterExp = "供货商、运营商")
    private String identity;

    /** 变更状态 */
    @Excel(name = "变更状态")
    private String status;

    public ChangeDetail(){

    }

    public ChangeDetail(PurchaseOrder purchaseOrder, List<OrderDetail> details, String changeDetail, String changePerson, String identity, String changeTime, String status) {
        this.orderNo = purchaseOrder.getOrderNo();
        this.responsiblePerson = purchaseOrder.getResponsiblePerson();
        this.contactPhone = purchaseOrder.getContactPhone();
        this.deliveryAddress = purchaseOrder.getDeliveryAddress();
        this.destinationLng = purchaseOrder.getDestinationLng();
        this.destinationLat = purchaseOrder.getDestinationLat();
        this.remarks = purchaseOrder.getRemarks();
        this.changeDetail = changeDetail;
        this.changePerson = changePerson;
        this.identity = identity;
        this.changeTime = changeTime;
        this.status = status;

        List<OrderDetail> orderDetails = new ArrayList<OrderDetail>();
        for(OrderDetail orderDetail : details){
            orderDetails.add(new OrderDetail(
                    orderDetail.getOrderDetailNo()
                    ,orderDetail.getOrderNo()
                    ,orderDetail.getRawProductBatch()
                    ,orderDetail.getExpectedDeliveryTime()
                    ,orderDetail.getQuantity()
                    ,orderDetail.getUnitPrice()));
        }
        ObjectMapper objectMapper = new ObjectMapper();
        String jsonString = null;
        try {
            jsonString = objectMapper.writeValueAsString(orderDetails);
        } catch (Exception e) {
            e.printStackTrace();
        }
        this.orderDetail = jsonString;
    }

    public ChangeDetail(String orderNo, String changeTime) {
        this.orderNo = orderNo;
        this.changeTime = changeTime;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }
    public void setOrderNo(String orderNo)
    {
        this.orderNo = orderNo;
    }

    public String getOrderNo()
    {
        return orderNo;
    }
    public void setChangeDetail(String changeDetail)
    {
        this.changeDetail = changeDetail;
    }

    public String getChangeDetail()
    {
        return changeDetail;
    }
    public void setChangePerson(String changePerson)
    {
        this.changePerson = changePerson;
    }

    public String getChangePerson()
    {
        return changePerson;
    }
    public void setChangeTime(String changeTime)
    {
        this.changeTime = changeTime;
    }

    public String getChangeTime()
    {
        return changeTime;
    }
    public void setIdentity(String identity)
    {
        this.identity = identity;
    }

    public String getIdentity()
    {
        return identity;
    }
    public void setStatus(String status)
    {
        this.status = status;
    }

    public String getStatus()
    {
        return status;
    }
    public String getResponsiblePerson() {
        return responsiblePerson;
    }

    public void setResponsiblePerson(String responsiblePerson) {
        this.responsiblePerson = responsiblePerson;
    }
    public String getContactPhone() {
        return contactPhone;
    }

    public void setContactPhone(String contactPhone) {
        this.contactPhone = contactPhone;
    }
    public String getDeliveryAddress() {
        return deliveryAddress;
    }

    public void setDeliveryAddress(String deliveryAddress) {
        this.deliveryAddress = deliveryAddress;
    }

    public double getDestinationLng() {
        return destinationLng;
    }

    public void setDestinationLng(double destinationLng) {
        this.destinationLng = destinationLng;
    }

    public double getDestinationLat() {
        return destinationLat;
    }

    public void setDestinationLat(double destinationLat) {
        this.destinationLat = destinationLat;
    }

    public String getRemarks() {
        return remarks;
    }

    public void setRemarks(String remarks) {
        this.remarks = remarks;
    }
    public String getOrderDetails() {
        return orderDetail;
    }

    public void setOrderDetails(String orderDetail) {
        this.orderDetail = orderDetail;
    }

    @Override
    public String toString() {
        return "ChangeDetail{" +
                "id=" + id +
                ", orderNo='" + orderNo + '\'' +
                ", responsiblePerson='" + responsiblePerson + '\'' +
                ", contactPhone='" + contactPhone + '\'' +
                ", deliveryAddress='" + deliveryAddress + '\'' +
                ", remarks='" + remarks + '\'' +
                ", orderDetail='" + orderDetail + '\'' +
                ", changeDetail='" + changeDetail + '\'' +
                ", changePerson='" + changePerson + '\'' +
                ", changeTime='" + changeTime + '\'' +
                ", identity='" + identity + '\'' +
                ", status='" + status + '\'' +
                '}';
    }
}
